" Better defaults

" Swap display lines and logical lines {{{1
" Remap j and k to move to the next line on the screen {{{2
nnoremap j gj
nnoremap k gk
nnoremap gj j
nnoremap gk k

xnoremap j gj
xnoremap k gk
xnoremap gj j
xnoremap gk k

" Remap $, ^ and 0 to applying to display lines {{{2
nnoremap $ g$
nnoremap ^ g^
nnoremap 0 g0
nnoremap g$ $
nnoremap g^ ^
nnoremap g0 0

xnoremap $ g$
xnoremap ^ g^
xnoremap 0 g0
xnoremap g$ $
xnoremap g^ ^
xnoremap g0 0

" Better cursor placement {{{1
" Automatically center the next search result to the middle of the screen {{{2
nnoremap n nzzzv
nnoremap N Nzzzv

xnoremap n nzzzv
xnoremap N Nzzzv

" keep centered when jumping forward and backward to recent changes {{{2
nnoremap g, g,zz
nnoremap g; g;zz

" Automatically jump to the end of the block after pasting {{{2
nnoremap <silent> p p`]
nnoremap <silent> P P`]

" Upper-case commands {{{1
" Yank till EOL {{{2
nnoremap Y y$

" Split the current line {{{2
nnoremap S i<cr><esc>l

" Map J and K to normal j and k. It helps avoid mistakes during visual line mode {{{2
xnoremap J j
xnoremap K k

" Sane visual mode {{{1
" Jump to the end of the block after yanking {{{2
xnoremap <silent> y y`]

" Maintain the default register aftering pasting over, also jump to the end of {{{2
" the pasted block
xnoremap <silent> p "_dP`]
xnoremap <silent> P "_dP`]

" Enable dot command to repeat in visual mode {{{2
xnoremap . :normal!.<cr>

" Keep text selected after manual indentation {{{2
xnoremap < <gv
xnoremap > >gv

